import { createRouter, createWebHistory } from "vue-router";
import LayOut from "@/LayOut/index.vue";
import { isLogin } from "@/utils/index";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      redirect: "/home",
   },
    {
      path: "/",
      // name: "主页",
      component: LayOut,
      children: [
        {
          path: "/home",
          name: "主页",
          icon: "HomeFilled",
          component: () => import("@v/HomePage/index.vue"),
        },
        {
          path: "/manage",
          name: "运维管理",
          icon: "Refresh",
          component:() => import("@v/manage/index.vue") ,
          children: [
            {
              path: "/parkingManage",
              name: "停车场管理",
              icon: "Menu",
              component: () => import("@v/ParkingManage/index.vue"),
              children: [
                {
                  path: "/addParking",
                  name: "新增停车场",
                  icon: "CirclePlusFilled",
                  component: () => import("@v/AddParking/index.vue"),
                },
                {
                  path: "/updateParking",
                  name: "修改停车场",
                  icon: "EditPen",
                  component: () => import("@v/UpdateParking/index.vue"),
                },
              ],
            },
            {
              path: "/parkingSpace",
              name: "停车位管理",
              icon: "List",
              component: () => import("@v/ParkingSpace/index.vue")
            },
          ],
        },
        {
          path: "/businessConfiguration",
          name: "业务配置",
          icon: "Briefcase",
          component: () => import("@v/BusinessConfiguration/index.vue"),
        
        },
        {
          path: "/setting",
          name: "设置",
          icon: "Tools",
          component: () => import("@v/SettingPage/index.vue"),
        
        },
        {
          path: "/userInfo",
          name: "用户中心",
          component: () => import("@v/UserInfo/index.vue"),
        
        }
      ],
    },
    {
      path: "/login",
      name: "登录",
      component: () => import("@v/Login/index.vue"),
    },
    {
      path: "/screen",
      name: "大屏可视化",
      component: () => import("@v/BigScreen/index.vue"),
    },
    {
      path: "/:pathMatch(.*)*",
      name: "notFound",
      component: () => import("@v/NotFound/index.vue"),
    },
  ],
});

//路由守卫
 router.beforeEach((to, from, next) => {
      if (to.path !== '/login') {
        if (isLogin()) {
          next()
        } else {
          next('/login')
        }
      } else {
        next()
      }
    })
export default router;
